/**
 * Created by yyt on 2017/3/21.
 */
var emailFlag=true;
var mobileFlag=true;
var passwordFlag=true;
var repassFlag=true;
function checkMobile(){
    var mobile=document.getElementById("mobile");
    var mobileZhengZe=/^1[3587]\d{9}$/;
    mobile.onfocus=function(){
        mobile.nextSibling.innerHTML="";
    }
    mobile.onblur=function() {
        if(mobile.value=="") {
            mobile.nextSibling.style.display = "inline";
            mobile.nextSibling.innerHTML = "请输入电话号码！";
            mobileFlag=false;
        }else if (!mobileZhengZe.test(mobile.value)) {
            mobile.nextSibling.style.display = "inline";
            mobile.nextSibling.innerHTML = "电话号码格式错误！";
            mobileFlag=false;
        }else{
            mobileFlag=true;
        }
    }
}

function checkEmail() {
    var email = document.getElementById("email");
    var reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    email.onfocus=function () {
        email.nextSibling.innerHTML="";
    }
    email.onblur = function () {
        if (email.value == "") {
            email.nextSibling.style.display = "inline";
            email.nextSibling.innerHTML = "请输入邮箱号！";
            emailFlag=false;
        }else if (!reg.test(email.value)) {
            email.nextSibling.style.display = "inline";
            email.nextSibling.innerHTML = "邮箱格式不正确！";
            emailFlag=false;
        }else{
            emailFlag=true;
        }
    }
}

function checkPassword(){
    var password = document.getElementById("password");
    var repass = document.getElementById("repass");
    password.onfocus=function(){
        password.nextSibling.innerHTML = "";
    }
    password.onblur=function(){
        if(password.value.length< 6){password.nextSibling.innerHTML="密码至少为6位！";passwordFlag=false;}
        else if(password.value==""){password.nextSibling.innerHTML="请输入密码!";passwordFlag=false;}
        else if (repass.value != password.value) {
            repass.nextSibling.style.color = "#c10000";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "两次密码不一致！";
            passwordFlag=false;
        }else{
            passwordFlag=true;
        }
    }
}

function checkRepass() {
    var password = document.getElementById("password");
    var repass = document.getElementById("repass");
    repass.onfocus=function(){
        repass.nextSibling.innerHTML = "";
    }
    repass.onblur = function () {
        if (repass.value != password.value) {
            repass.nextSibling.style.color = "#c10000";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "两次密码不一致！";
            repassFlag=false;
        } else {
            repass.nextSibling.style.color = "green";
            repass.nextSibling.style.display = "inline";
            repass.nextSibling.innerHTML = "验证通过";
            repassFlag=true;
            passwordFlag=true;
        }
    }
}
function checkAll(){
    if(repassFlag && passwordFlag && mobileFlag && emailFlag){return true;}
    else{return false;}
}

    checkEmail();
    checkMobile();
    checkRepass();
    checkPassword();
    console.log("XXX");



